package cn.edu.scau.cmi.liuxintong;
import org.hibernate.Session;  
import org.hibernate.SessionFactory;  
import org.hibernate.cfg.Configuration;  
import org.hibernate.service.ServiceRegistry;  
import org.hibernate.service.ServiceRegistryBuilder;  
public class ScauCmiHibernateSessionFactoryUtil {
	private static SessionFactory sessionFactory;
//	sessionFactory单例
	
	public static SessionFactory getSessionFactory() {
		if(sessionFactory==null) {
			Configuration configuration = new Configuration().configure();
			ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); 
			sessionFactory=configuration.buildSessionFactory(serviceRegistry);
		}
		return sessionFactory;
	}

	public static Session getSession(){
		 Session session=getSessionFactory().openSession();
		return session;
	}
}
